 
local menu = model.__new( _CONF["mysql"] , "mysql");


--[[
- @desc   获取文章条数 
--]]
menu.table = 'mg_admin_menu';

 

--[[
- @desc    一条 
- @param  table   option 数据
- return  int   自增id
--]]
function menu:geturl() 
     local sql = 'SELECT * FROM  ' .. self.table .. ' WHERE visible = 1 AND url LIKE "%'.. _URI ..'%" limit 1';  
     local res, err, errno, sqlstate = self.execute(sql);
     return res[1];
end

--[[
- @desc   获取 menu_id 
- @param  table   option 数据
- return  int   自增id
--]]
function menu:getMenuId(parent_id)
     local sql = 'SELECT * FROM  ' .. self.table .. ' WHERE visible = 1 AND menu_id = '.. parent_id ..' limit 1';  
     local res, err, errno, sqlstate = self.execute(sql);
     return res[1];
end

--[[
- @desc   多条  
- @param  table   option 数据
- return  int   自增id
--]]
function menu:getall()
	 local curUrls3 = self:geturl();	--获取当前url 信息
  
     local sql = 'SELECT * FROM  ' .. self.table .. ' WHERE visible = 1';  
     local res, err, errno, sqlstate = self.execute(sql);
     
     local menutree = {};  -- 总的树形 
     local menuone = {};
     local menutwo = {};
     local menuthree = {};
      
     local i = 1;
     for k, v in pairs(res) do   
        if  v['parent_id'] == 0 then
            menutree[i] = v;
            menuone[i] = v;
            i = i +1;
        end 
     end
      
      local j = 1;  
      for k, v in pairs(res) do   
           for key, val in pairs(menutree) do 
                 if not menutree[key]['child'] then 
                      menutree[key]['child'] = {}; 
                 end
                 
                 if res[k]['parent_id'] == val['menu_id'] then 
                     menutree[key]['child'][j] = v; 
                    
                     menutwo[j] = v;
                     j = j +1;
                 end
            end
      end
         
      local m = 1;  
      for k, v in pairs(res) do   
           for key, val in pairs(menutree) do   
                for keys ,vals in pairs(val['child']) do
                     ------------------是否显示start----------------   
                      if res[k]['parent_id'] == curUrls3['menu_id'] then
                          menutree[key]['child'][keys]['pview'] = 1;
                      end
                      
                      if res[k]['menu_id'] == curUrls3['menu_id'] then
                          menutree[key]['child'][keys]['sview'] = 1;
                      end
                     -------------------是否显示end----------------  
                     
                      
                      if not  menutree[key]['child'][keys]['child'] then
                          menutree[key]['child'][keys]['child'] = {};
                       end
                      
                      if res[k]['parent_id'] == vals['menu_id'] then  
	                      menutree[key]['child'][keys]['child'][m] = v;   
                          menuthree[m] = v; 
                          m = m +1;
                      end
                end  
           end 
      end 
      
      return  menuone, menutwo, menuthree,  menutree; 
end 



return menu;